<?php
class Somi_Form_Auftrag extends Zend_Dojo_Form
{
	public function init()
	{
		
		$this->setName('Auftragdaten');
		$this->setAction($this->getView()->url())->setMethod('post');
		$this->addAttribs(array('onSubmit'=>'return validate(this)'));
		
		require_once APPLICATION_BASE.'/library/Somi/Validate/ErrorMessageDe.php';
		
		$translateValidators= new Somi_Validate_ErrorMessageDe();
		$translator = new Zend_Translate('array', $translateValidators->getTranslate());
    	Zend_Validate_Abstract::setDefaultTranslator($translator);
    	
    	#$this->clearDecorators();
		$formDecorators=array(
            'FormElements',
        array('HtmlTag',array('tag'=>'dl','class'=>'zend_form')),
            'DijitForm', // hier stand bei dir vorher: 'Form',
        );
                
        
        $elementDecorators=array(
        'DijitElement', // vorher: 'ViewHelper',
        'Errors',
        array(array('data'=>'HtmlTag'),array('tag'=>'div','class'=>'element')),
        array('Label',array('class'=>'left','requiredSuffix' => '*')),
        array(array('row'=>'HtmlTag'),array('tag'=>'div','class'=>'row')),
        );
        
        $buttonDecorators=array(
        'DijitElement', // vorher: 'ViewHelper',
        array(array('data'=>'HtmlTag'),array('tag'=>'div','class'=>'button')),
        array(array('row'=>'HtmlTag'),array('tag'=>'div'))
        );  
		
	
		$filterToLower = new Zend_Filter_StringToLower();
        $filterToLower->setEncoding('UTF-8');
        
        
        $auftrag=new Somi_Models_Auftrag();
        $statusen=$auftrag->getStatus();
        $supportarten=$auftrag->getSupportart();
       	$firmen= new Somi_Models_Firma();
        $firmens=$firmen->getAll();
        
        #Datum von
        $datum_von=$this->createElement('DateTextBox','datum_von',array(
        'label'          => 'Datum von',
        'required'       => false,
        'invalidMessage' => 'Ungültiges Datum spezifiziert.',
        #'formatLength'   => 'long',
         'style'			=> 'width:245px;',
	     )
	     );
	     
	     
	     #Datum von
        $datum_bis=$this->createElement('DateTextBox','datum_bis',array(
        'label'          => 'Datum bis',
        'required'       => false,
        'invalidMessage' => 'Ungültiges Datum spezifiziert.',
        'validators'	=> array('NotEmpty',), 
        #'formatLength'   => 'long',
         'style'			=> 'width:245px;',
	     )
	     );
	     
        
	     #status
        $status = $this->createElement('FilteringSelect','status',array(
		'label'        => 'Status',
        'value'        => '',
        'autocomplete' => false,
        'style'			=> 'width:245px;',
        ));
		foreach($statusen as $v)
        {
        	$status->addMultiOption($v,$v);
        }
        
		#supportart
        $supportart = $this->createElement('FilteringSelect','supportart',array(
		'label'        => 'Supportart',
        'value'        => '',
        'autocomplete' => false,
        'style'			=> 'width:245px;',
        ));
		foreach($supportarten as $v)
        {
        	$supportart->addMultiOption($v,$v);
        }
        
        
        
        #Techniker
        $techniker=$this->createElement('ValidationTextBox','techniker',array(
        'label'			=> 'Techniker',
        'alnum'			=>true,
        'required'		=> false,
        'PromptMessage'		=> '<div style="width:200px">z.B. Max Muster</div>', 
        'style'			=> 'width:245px;', 
        'filters'		=> array($filterToLower,),
        #'validators'	=> array('NotEmpty',), 
        ));
        
        
		#firma
        $firma= $this->createElement('FilteringSelect','firma_id',array(
		'label'        => 'Firma',
        'value'        => '',
        'autocomplete' => false,
        'style'			=> 'width:245px;',
        ));
		foreach($firmens as $v)
        {
        	$firma->addMultiOption($v['firma_id'],$v['firma']);
        }
        
        
       #Beschreibung
		$beschreibung=$this->createElement('Textarea','beschreibung',array(
		'label'		=> 'Beschreibung',
		#'style'		=>'height:100px;width:300px;',
		#'height'		=>'100px',
		#'PromptMessage'		=> '<div style="width:200px">Noch mher Input</div>',
		'style'    => 'width: 248px; height: 100px;',
		'required'	=> false,
		));       
        
        
        $submit=$this->createElement('SubmitButton','submit',array(
        'label'			=> 'Senden',
        'style'			=> 'margin-left:308px;width:200px;',
        ));
        
        
        
        $this->addElements(array($firma,$datum_von,$datum_bis,$status,$supportart,$techniker,$beschreibung,$submit));
        
	}
}